package com.ldzl.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ldzl.dto.ArrivalNoticeDTO;
import com.ldzl.dto.ArrivalStorageRequestDTO;
import com.ldzl.pojo.CkPurchaseOrder;
import com.ldzl.pojo.CkPurchaseOrderLine;
import com.ldzl.service.CkPurchaseOrderLineService;
import com.ldzl.mapper.CkPurchaseOrderLineMapper;
import com.ldzl.service.CkPurchaseOrderService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

/**
* @author 风止
* @description 针对表【ck_purchase_order_line(采购订单详情表)】的数据库操作Service实现
* @createDate 2025-07-11 11:17:44
*/
@Service
@Transactional
public class CkPurchaseOrderLineServiceImpl extends ServiceImpl<CkPurchaseOrderLineMapper, CkPurchaseOrderLine>
    implements CkPurchaseOrderLineService{

    /**
     * 查询采购订单详情 未到货
     * @param po
     * @return
     */
    @Override
    public List<ArrivalNoticeDTO> selectArrivalNotice(CkPurchaseOrder po) {
        return super.baseMapper.selectArrivalNotice(po);
    }

    /**
     * 查询可入库的 采购订单详情
     * @param arr
     * @return
     */
    @Override
    public List<ArrivalNoticeDTO> selectOrderStore(ArrivalNoticeDTO arr) {
        return super.baseMapper.selectOrderStore(arr);
    }

    /**
     * 根据ID 查询采购订单详情
     * @param po_id
     * @return
     */
    @Override
    public List<CkPurchaseOrderLine> selectOrderLine_id(Long po_id) {
        return super.list(new QueryWrapper<CkPurchaseOrderLine>()
                .eq("is_delete",0)
                .eq("po_id",po_id)
                .orderByDesc("update_time")
        );
    }

    /**
     * 移除指定的采购商品
     * @param line_id
     * @return
     */
    @Override
    public boolean updateIs_delete(Long line_id) {
        return super.baseMapper.updateIs_delete(line_id) > 0;
    }

    /**
     * 移除指定采购订单的采购商品
     * @param po_id
     * @return
     */
    @Override
    public boolean updateIs_delete_line(Long po_id) {
        return super.baseMapper.updateIs_delete_line(po_id) > 0;
    }

    /**
     * 更新采购商品待上架数量
     * @param line_id
     * @param receipt_num
     * @return
     */
    @Override
    public boolean updateArrived_num(Long line_id, BigDecimal receipt_num) {
        return super.baseMapper.updateArrived_num(line_id, receipt_num) > 0;
    }

    /**
     * 商品上架
     * @param line_id
     * @param receipt_num
     * @return
     */
    @Override
    public boolean updateList_num(Long line_id, BigDecimal receipt_num) {
        return super.baseMapper.updateList_num(line_id, receipt_num) > 0;
    }

    /**
     * 采购商品待上架数量回滚
     * @return
     */
    @Override
    public boolean updateArrived_num_back(Long line_id, BigDecimal receipt_num) {
        return super.baseMapper.updateArrived_num_back(line_id, receipt_num) > 0;
    }

    /**
     * 批量更新采购商品已上架数量
     * @param lineIds
     * @return
     */
    @Override
    public boolean updateTreat_list_num(List<Long> lineIds) {
        return super.baseMapper.updateTreat_list_num(lineIds) > 0;
    }

    /**
     * 修改到货数量
     * @param line_id
     * @param delivery_num
     * @return
     */
    @Override
    public int updateArrivalStorage(Long line_id, BigDecimal delivery_num) {
        return super.baseMapper.updateArrivalStorage(line_id, delivery_num);
    }

    /**
     * 获取订单下的待收货数量 之和
     * @param po_id
     * @return
     */
    @Override
    public BigDecimal waitNumSum(Long po_id) {
        return super.baseMapper.waitNumSum(po_id);
    }


}




